package com.gzy.android_douban.ui.home;

import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Toast;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;

import com.gzy.android_douban.R;
import com.gzy.android_douban.databinding.FragmentHomeBinding;
import com.gzy.android_douban.ui.BaseFragment;
import com.gzy.android_douban.ui.MyAdapter;
import com.gzy.android_douban.ui.News;

import java.util.ArrayList;
import java.util.List;


public class HomeFragment extends BaseFragment<FragmentHomeBinding> {
  FragmentHomeBinding binding;
  private RecyclerView recyclerView;

  @Override public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceState) {
    super.onViewCreated(view, savedInstanceState);


  }

  @Override
  public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
//    return super.onCreateView(inflater, container, savedInstanceState);
    binding = FragmentHomeBinding.inflate(inflater, container,false);
    View view = binding.getRoot();

    initClick();
    assembleInit();

    return view;
  }


  private void assembleInit() {
    List<News> newsList = new ArrayList<>();
    News news1 = new News(R.drawable.tutu001,"标题1","文字怎自身的那份牛市的发挥市场牛231文字怎自身的那份牛市的发挥市场牛231文字怎自身的那份牛市的发挥市场牛231文字怎自身的那份牛市的发挥市场牛231");
    News news2 = new News(R.drawable.tutu002,"标题2","是丢你发丢viu的v牛啊四季豆巨热");
    newsList.add(news1);
    newsList.add(news2);

    LinearLayoutManager layoutManager = new LinearLayoutManager(getActivity());
    binding.recyclerView.setLayoutManager(layoutManager);
    MyAdapter myAdapter = new MyAdapter(newsList);

    binding.recyclerView.setAdapter(myAdapter);
  }

  private void initClick() {
    binding.tvTuijian.getPaint().setFakeBoldText(true);
    binding.tvTuijian.setTextSize(24);
    binding.tvTuijian.setOnClickListener(new View.OnClickListener() {
      @Override
      public void onClick(View v) {
        binding.tvTuijian.getPaint().setFakeBoldText(true);
        binding.tvTuijian.setTextSize(24);
        binding.tvGuangchang.getPaint().setFakeBoldText(false);
        binding.tvGuangchang.setTextSize(20);
        binding.tvRebang.getPaint().setFakeBoldText(false);
        binding.tvRebang.setTextSize(20);
      }
    });

    binding.tvGuangchang.setOnClickListener(new View.OnClickListener() {
      @Override
      public void onClick(View v) {
        binding.tvTuijian.getPaint().setFakeBoldText(false);
        binding.tvTuijian.setTextSize(20);
        binding.tvGuangchang.getPaint().setFakeBoldText(true);
        binding.tvGuangchang.setTextSize(24);
        binding.tvRebang.getPaint().setFakeBoldText(false);
        binding.tvRebang.setTextSize(20);
      }
    });

    binding.tvRebang.setOnClickListener(new View.OnClickListener() {
      @Override
      public void onClick(View v) {
        binding.tvTuijian.getPaint().setFakeBoldText(false);
        binding.tvTuijian.setTextSize(20);
        binding.tvGuangchang.getPaint().setFakeBoldText(false);
        binding.tvGuangchang.setTextSize(20);
        binding.tvRebang.getPaint().setFakeBoldText(true);
        binding.tvRebang.setTextSize(24);
      }
    });

    binding.imgbtnSearch.setOnClickListener(new View.OnClickListener() {
      @Override
      public void onClick(View v) {
        Toast.makeText(getActivity(), "1212", Toast.LENGTH_SHORT).show();
        Intent intent = new Intent(getActivity(), SearchActivity.class);
        startActivity(intent);
      }
    });
  }
}